package utils

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"strings"
)

var url = "http://eid.shumaidata.com/eid/check"
var AppCode = "27e94c2b63c14c2d95cc688705bf0f3f"

func CardTest(realName string, idCard string) (map[string]interface{}, error) {

	//创建一个http 客户端
	client := http.Client{}
	body := "name=" + realName + "&idcard=" + idCard
	//访问接口
	req, err := http.NewRequest("POST", url, strings.NewReader(body))
	if err != nil {
		return nil, err
	}
	//给请求 数据加上格式 并且还有 code 验证
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Authorization", "APPCODE "+AppCode)

	resq, err := client.Do(req)
	//关闭请求
	defer resq.Body.Close()
	//读取
	b, e := io.ReadAll(resq.Body)
	if e != nil {
		return nil, e
	}
	fmt.Println(string(b))

	var m map[string]interface{}

	json.Unmarshal(b, &m)
	return m, nil
}
